<?php

namespace Controller;

//Controller för nytt inlägg
class PostNewController {
	/**
	 * @return String $xhtml
	 */

	public function DoControll($database) {
		$xhtml = "";
		$messageid = 0;
		$message = "";

		$postView = new \View\PostView();
		$ph = new \Model\PostHandler($database);

		if ($postView -> TriedToSubmit()) {
			$messageid = $ph -> newPost($postView -> Title(), $postView -> Content());

			if ($messageid == \Model\PostHandler::POST_EMPTY) {
				$message .= $postView -> NewPostMess(\View\PostView::POST_EMPTY);
			}
			if ($messageid == \Model\PostHandler::POST_SUCCESS) {
				$message .= $postView -> NewPostMess(\View\PostView::POST_SUCCESS);

			}
			if ($messageid == \Model\PostHandler::POST_FAILED) {
				$message .= $postView -> NewPostMess(\View\PostView::POST_FAILED);
			}
		}

		$xhtml .= $message;
		$xhtml .= $postView -> NewPostForm();

		return $xhtml;
	}

}
